<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>users</title>
<jsp:include page="header.jsp"></jsp:include>
<script type="text/javascript">
$(function(){
	//分页显示用户列表
	$('#dg').datagrid({     
	   		title:'添加商铺',
			iconCls:'icon-save',
			fitColumns:true,
			striped:true,
			pagination:true,
			rownumbers:true,
			fit:true,
			toolbar: [{
				iconCls: 'icon-add',
				handler: showAddDialog,
				text:'请添加您的商铺',
			}]
	}) 
	
});
//2.添加操作，添加先显示对话框让用户输入
function showAddDialog(){
	//清空form
	$("#addDialog #ff").form("clear");
	$("#addDialog").dialog("open");
}
 //关闭新增窗口
function closeAddDialog(){
	$("#addDialog").dialog("close");
}
//保存新增数据
function addSubmit(){
	$("#addDialog #ff").form('submit', {    
	    url:'../shop/add',   
	    onSubmit: function(){    
	        // 做一些验证，提交数据是否合法
	        return $(this).form('validate');

	        // return false to prevent submit;    
	    },    
	    success:function(data){ //这个data不是json对象而是一个字符串 
	    	var message=JSON.parse(data);	    
	    	$.messager.show({
				title:'提示消息',
				msg:message.msg,
				timeout:2000,
				showType:'slide'
			});
	    	if(message.success){
	    		$("#dg").datagrid("reload");
	    		$("#addDialog").dialog("close");
	    	}    
	    }    
	});  
}

</script>
</head>
<body>
	<table id="dg"></table> 
	<div id="addDialog" class="easyui-dialog" title="新增商铺" style="width:600px;padding:10px;"   
        data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,buttons:[{
				text:'保存',
				handler:addSubmit
			},{
				text:'关闭',
				handler:closeAddDialog
			}]">

    <form id="ff" method="post" enctype="multipart/form-data">
   	<table style="width:100%;">
    	<tr>
	    	<td>商铺名:</td>
	    	<td>
	    	<input class="easyui-textbox" name="sname" style="width:100%" data-options="required:true,validType:'length[4,15]'">
	    	</td>
    	</tr>
    	<tr>
	    	<td>店铺简介:</td>
	    	<td>
	    	<input class="easyui-textbox"  name="summary" style="width:100%" data-options="required:true,validType:'length[4,115]'">
	    	</td>
    	</tr>
    	<tr>
	    	<td>店铺头像:</td>
	    	<td>
	    	<input type="file" name="spic" style="width:100%;">
	    	</td>
    	</tr>	
    </table>
	</form>
	</div>  
</body>
</html>